package org.atlantis.grosbeak.logger.adapter;

/**
 * System日志实现。使用System.out或System.err对日志进行输出。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">SeeNoEvil</a>
 * 
 */
class SystemLogger extends BaseLogger {

	private static SystemLogger sysLogger = new SystemLogger();

	static SystemLogger me() {
		return sysLogger;
	}

	private SystemLogger() {
	}

	public void debug(Object message, Throwable cause) {
		if (isDebugEnabled())
			outPrint(message, cause);
	}

	public void error(Object message, Throwable cause) {
		if (isErrorEnabled())
			errPrint(message, cause);
	}

	public void fatal(Object message, Throwable cause) {
		if (isFatalEnabled())
			errPrint(message, cause);
	}

	public void info(Object message, Throwable cause) {
		if (isInfoEnabled())
			outPrint(message, cause);
	}

	public void trace(Object message, Throwable cause) {
		if (isTraceEnabled())
			outPrint(message, cause);
	}

	public void warn(Object message, Throwable cause) {
		if (isWarnEnabled())
			errPrint(message, cause);
	}

	private void outPrint(Object message, Throwable cause) {
		System.out.println(message);
		if (cause != null)
			cause.printStackTrace(System.out);
	}

	private void errPrint(Object message, Throwable cause) {
		System.err.println(message);
		if (cause != null)
			cause.printStackTrace(System.err);
	}
}
